﻿using MvcArchStarter.Core.Persistence;
using MvcArchStarter.Domain;
using MvcArchStarter.WebUI.Core;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace MvcArchStarter.WebUI.Controllers.PostsCommands
{
    public class PostBlogPostCommand : IPostCommand<Post>
    {
        public IUnitOfWork UnitOfWork { get; set; }

        public Post ViewModel { get; set; }

        public void Execute()
        {
            var blog = UnitOfWork.RepositoryOf<Blog>().FindWhere(_ => _.BlogID == ViewModel.BlogId).FirstOrDefault();

            blog.Posts.Add(ViewModel);

            UnitOfWork.SaveChanges();
        }
    }
}